//添加任务
function init() {
    	$("#ord_you").click(function(){
    		$("#dl_ord_info").css('display','');
    	});
		$("#ord").click(function(){
    		$("#dl_ord_info").css('display','none');
    	});
        $("#test_shi").click(function(){
    		$("#test_issue").show();
    		$("#dl_test").css('display','none');
    	});
		$("#test_fou").click(function(){
    		$("#dl_test").css('display','');
    		$("#test_issue").hide();
    	});
		$("#re_type_time_fou1").click(function(){
    		$("#dl_release_type").css('display','none');
    	});
		$("#re_type_time_fou2").click(function(){
    		$("#dl_release_type").css('display','none');
    	});
		$("#re_type_time").click(function(){
    		$("#dl_release_type").css('display','');
    	});
		$("#restart_daemon").click(function(){
    		$("#dl_daemon_name").css('display','');
    	});
		$("#restart_daemon_fou").click(function(){
    		$("#dl_daemon_name").css('display','none');
    	});
		$("#js_css").click(function(){
    		$("#dl_js_css").css('display','');
    	});
		$("#js_css_fou").click(function(){
    		$("#dl_js_css").css('display','none');
    	});
		$("#submit_btn").click(function(){
			$("#show_text").html('确定要提交吗？');
			var p = $("#submit_btn").offset();
			$("#add_check").css('left',p.left+100);
			$("#add_check").css('top',p.top-300);
            $("#add_check").css('display','');
    	});
		$("#add_check_yes").click(function(){
			$("#add_check").css('display','none');
			$("#form1").attr('target','addiframe');
    		$("#form1").submit();
			
    	});
		$("#add_check_no").click(function(){
            $("#add_check").css('display','none');
    	});
		$("#add_check_close").click(function(){
            $("#add_check").css('display','none');
    	});
		
		

		$("#class1").change(function(){
			   var index = $(this).val();
			   $.get("/release/aj_model.php?id="+index, "", function(rs){
					var _msg = eval("("+rs+")");
					if(_msg.result.model2){
						$("#class2").html(_msg.result.model2);
					}
					if(_msg.result.staff){
						$("#pub_product_staff").val(_msg.result.staff.pub_product_staff);
						$("#pub_tec_staff").val(_msg.result.staff.pub_tec_staff);
					}
			   });
		});

		$("#dept_id1").change(function(){
			   var index = $(this).val();
			   $.get("/release/aj_dept.php?id="+index, "", function(rs){
					var _msg = eval("("+rs+")");
					if(_msg.result){
						$("#dept_id2").html(_msg.result);
					}
					
			   });
		});

		//全选，反选
	   $("#chose_btn").click(function(){
				var type = $(this).attr("rel");	//type=1 全选 type=0返选
				if(type==0){
					$(".release_ids").each(function(){
						$(this).attr('checked',true);
					});
					$("#chose_btn").attr("rel","1");
				}else{
					$(".release_ids").each(function(){
						$(this).attr('checked',false);
					});
					$("#chose_btn").attr("rel","0");
			    }
				
		});
       //通过
       $("#yes_click_all").bind('click',function() {
            var rids = new Array();
            $(".release_ids").each(function(){
                var checked = $(this).attr('checked');
                if(checked == true) {
                    rids.push($(this).val());
                }
            });
            if(rids.length==0) {
                alert('至少选择一个');
                return;
            }
            if(!confirm("确定操作吗？")) {
                return;
            }
            rids = rids.join(',')
            console.log(rids);

            $.ajax({
                type: "GET",
                url: "/release/apply_tongguo.php?ids="+rids,
                dataType: "json",
                success: function(json){
                    if(json.errno == 1) {
                        alert(json.msg);
                        location.href = location.href;
                    }else {
                        alert(json.msg);
                    }
                }
            }); 
            //window.location.href="/release/apply_res.php?ac=yes&id="+rids;
            //$(this).unbind('click'); 
       });
       $("#tongguo").click(function(){
			  var id = $(this).attr('rel');
			  var p = $("#tongguo").offset();
			  $("#tongguo_div").css('top',p.top-200);
			  $("#tongguo_div").css('left',p.left+100);
		      $("#tongguo_div").css('display','');
			  $("#tong_id").val(id);
	    });
		$("#bohui").click(function(){
			  var id = $(this).attr('rel');
			  var p = $("#bohui").offset();
			  $("#bohui_div").css('top',p.top-200);
			  $("#bohui_div").css('left',p.left+100);
		      $("#bohui_div").css('display','');
			  $("#bo_id").val(id);
	    });


         
		$(".tongguo").click(function(){
			  var id = $(this).attr('rel');
			  var p = $(this).offset();
			  $("#tongguo_div").css('top',p.top-200);
			  $("#tongguo_div").css('left',p.left-400);
		      $("#tongguo_div").css('display','');
			  $("#tong_id").val(id);
	    });

        $("#tongguo_yes").bind('click',function() {
			  var id =$("#tong_id").val();
              $(this).unbind('click');
			  window.location.href="/release/apply_res.php?ac=yes&id="+id;
        });
        /*
		$("#tongguo_yes").click(function(){
			  var id =$("#tong_id").val();
              $(this).removeAttr("id");
			  window.location.href="/release/apply_res.php?ac=yes&id="+id;
	    });
        */
		$("#tongguo_no").click(function(){
			  $("#tongguo_div").css('display','none');
			  $("#tong_id").val('');
	    });
		$("#tongguo_close").click(function(){
			  $("#tongguo_div").css('display','none');
			  $("#tong_id").val('');
	    });


		$(".bohui").click(function(){
			  var id = $(this).attr('rel');
			  var p = $(this).offset();
			  $("#bohui_div").css('top',p.top-200);
			  $("#bohui_div").css('left',p.left-400);
		      $("#bohui_div").css('display','');
			  $("#bo_id").val(id);
	    });
		$("#bohui_yes").click(function(){
			  var id =$("#bo_id").val();
			  var reason =$("#reason").val();
			  window.location.href="/release/apply_res.php?ac=no&id="+id+"&reason="+reason;
	    });
		$("#bohui_no").click(function(){
			  $("#bohui_div").css('display','none');
			  $("#bo_id").val('');
	    });
		$("#bohui_close").click(function(){
			  $("#bohui_div").css('display','none');
			  $("#bo_id").val('');
	    });

		

		
		
}
var staff_history = [];
var staff_cache = [];
function autoshow_staff(){
	$('.staff_auto_show').keyup(function(event){
		hide_staff_list();
		var inputname = $(this).attr('name');
		var myEvent = event || window.event;
		var keyCode = myEvent.keyCode;
		if ((keyCode>=65&&keyCode<=90)||(keyCode>=48&&keyCode<=57)||(keyCode>=96&&keyCode<=105)||keyCode==8||keyCode==46){
			var val = get_input_staff_val(inputname);
			if(!val || getLength(val)<3){
				return false;
			}
			if(staff_cache[val]){
				show_staff_list(inputname, staff_cache[val]);
			}else{
				var url = "aj_staff_list.php";
				setTimeout(function(){
					if(val == get_input_staff_val(inputname) && !staff_history[val]){
						staff_history[val] = 1;
						$.ajax({
						  	url: url,
					        type: "get",
					        data: {'staff':val},
					        dataType: "json",
					        success: function(msg){
					  			if(msg.code == 1000){
					  				staff_cache[val] = msg.data;
					  				show_staff_list(inputname, msg.data);
					  	  		}else{
					  	  			staff_history[val] = 0;
					  	  			hide_staff_list();
					  	  		}
					  		}
					   });
					}else{
						hide_staff_list();
					}
				}, 100);
			}
		}
	});
	$(".select_product_staff").live('click', function(){
		var staff = $.trim($(this).html());
		$('input[name=product_staff]').val(staff);
		hide_staff_list();
	});
	$(".select_att_staff").live('click', function(){
		var staff = $.trim($(this).html());
		var val = $("input[name=att_staff]").val();
		var strs= new Array();
		strs = val.split(';');
		strs.pop();
		if(strs.length == 0){
			$('input[name=att_staff]').val(staff+";");
		}else{
			$('input[name=att_staff]').val(strs.join(';')+";"+staff+";");
		}
		hide_staff_list();
	});
}
function get_input_staff_val(inputname){
	var val = $('input[name='+inputname+']').val();
	if(inputname=='att_staff'){
		var strs= new Array();
		strs = val.split(';');
		return strs.pop();
	}
	return val;
}
function show_staff_list(id, data){
	var html = '<ul>';
	for(i in data){
		html += '<li><a href="javascript:void(0);" class="select_'+id+'">'+data[i].staff+'</a>';
		if(data[i].name){
			html += '（'+data[i].name+'）</li>';
		}
	}
	html += '</ul>';
	$('#'+id+'_show').html(html);
	$('#'+id+'_show').css('display','');
}
function hide_staff_list(){
	$(".staff_list_show").css('display','none');
}
function getLength(val){
	var _length = 0
	for (var i = 0; i < val.length; i++) {
        if (val.charCodeAt(i) > 255) {
            _length = _length + 2;
        }else {
            _length++;
        }
    }
	return _length;
}
$(document).ready(function(){init();autoshow_staff();});
